<template>
  <el-row>
    <el-tooltip
        class="box-item"
        effect="dark"
        content="获取设备MQTT连接参数"
        placement="top-start"
    >
      <el-button @click="this.init">更新参数</el-button>
    </el-tooltip>
  </el-row>
  <el-row>
    <el-alert type="info" show-icon :closable="false">
      <template #title>
        <el-text size="small">注意：这里仅仅为 临时调试 所用，密钥有效期为 5 分钟，真实设备连接参数请按加密文档生成。</el-text>
      </template>
    </el-alert>
  </el-row>
  <el-row>
    <highlight :code="code" language="json"/>
  </el-row>
</template>
<script>
import {getDeviceMqttLinks} from "@/api/iot/mqtt/links";
import {validatenull} from "@/utils/validate";

export default {
  name: 'deviceMqtt',
  props: {
    deviceId: String,
  },
  data() {
    return {
      code: "",
      activeName: "input",
    };
  },
  watch: {
    deviceId() {
      this.init();
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      if (validatenull(this.deviceId)) {
        return;
      }
      getDeviceMqttLinks(this.deviceId).then(res => {
        this.code = JSON.stringify(res.data.data);
      });
    },
    onCopySuccess() {
      this.$message.success('复制成功');
    }
  }
};
</script>
<style>

.code {
  width: 300px;
  height: 300px;
}
</style>
